package com.estacionamientos

import org.springframework.web.context.support.WebApplicationContextUtils

//http://localhost:8080/estacionamientos/email?to=lischettim@gmail.com&subject=estacionamientos&body=Esto+es+un+mensaje+automatico+de+losEstacionamientos.com
class EmailController {
	def emailService
	def appCtx = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext)
	
    // Send an email
    def index = {
        // Each "email" is a simple Map
        def email = [
            to: [ params.to ],        // "to" expects a List, NOT a single email address
            subject: params.subject,
            text: params.body         // "text" is the email body
        ]
        // sendEmails expects a List
		try{
			emailService.sendEmails([email])
		}catch(org.springframework.mail.MailSendException e){
			e.printStackTrace();
		}
        render("done")
    }
	
	def enviarEmail = {
		def email = [
			to: [ params.to ],        // "to" expects a List, NOT a single email address
			subject: params.subject,
			text: params.body         // "text" is the email body
		]
		// sendEmails expects a List
		try{
			emailService.sendEmails([email])
		}catch(org.springframework.mail.MailSendException e){
			e.printStackTrace();
		}
		render("listo vieja")

	}
}
